const { ccclass, property } = cc._decorator;
declare let eManager,dbh,DBManager,i18n,JsonHttp;
import BaseView from "../../component/BaseView";
import HzMiniSelectIconList from "./HzMiniSelectIconList";
import Utils = require("../../utils/Utils");
import PopUIHelper = require("../../utils/PopUIHelper");
import UIHelper = require("../../component/UIHelper");
@ccclass
export default class RepairMouthView extends BaseView {
    @property(HzMiniSelectIconList)
    selectList: HzMiniSelectIconList = null;

    @property(cc.Node)
    guideNodeList: cc.Node[] = [];

    @property(sp.Skeleton)
    mouthSpine: sp.Skeleton = null;

    @property(cc.Node)
    endNode: cc.Node = null;
    @property(cc.Node)
    btnClose: cc.Node = null;
    _point = 1;//第几步
    _isPlay = false;
    _Step = ["yaquan","zuanzi","yaquan","zuanzi","yasheban","gouzi"];//第九关
    _StepList = [1,2,3,4,5,5,6,6];//8个步骤
    _StepNum = 6;//6关
    _isStart = false;//是否是剧情前触发
    onLoad() {
        super.onLoad();
        //@ts-ignore
        this._isStart = this.node.openParam;
        Utils.audioManager.stopBGM();
    };

    onClose(){
        Utils.audioManager.playDefaultBGM();
    };

    start(){
        super.start();
        if(this.btnClose){
            this.btnClose.active = !this._isStart;
        }
        this.selectList.showList(this._Step, this._StepNum, 1);
        this.mouthSpine.setCompleteListener(() => {
            this.showGuide();
        });
        Utils.audioManager.playSound("huazhuang/mini/mini_step9_0");
        this.mouthSpine.setAnimation(0, "00", false);
    };

    showGuide(){
        let guide = this.guideNodeList[this._point-1];
        if(guide){
            guide.active = true;
        }
    };

    onClickPlay(event,index){
        let _index = parseInt(index);
        if(this._isPlay)
            return;
        let guide = this.guideNodeList[_index-1];
        if(guide){
            guide.active = false;
        }
        this.mouthSpine.setCompleteListener(() => {
            this._point++;
            let curPoint = this._StepList[this._point - 1];
            if(curPoint == null){
                curPoint = this._StepList[this._StepList.length - 1];
            }
            this.selectList.showList(this._Step, this._StepNum, curPoint);
            this._isPlay = false;
            this.showGuide();
            this.showPlayEnd();
        });
        Utils.audioManager.playSound("huazhuang/mini/mini_step9_" + index);
        this.mouthSpine.setAnimation(0, "0" + index, false);
        // Initializer.huaZhuangProxy.sendMakeDot(3,index,1);
        this._isPlay = true;
    };

    showPlayEnd(){
        if(this._point <= this._StepList.length)
            return;
        this.endNode.active = true;
        Utils.audioManager.playSound("huazhuang/mini/mini_jiesuan");
    };

    onClickEnd(isSkip){
        let next = this.params.next && this.params.next.shift();
        if (next) {
            UIHelper.openUI(next, {
                next: this.params.next
            })
            this.node.destroy();
        }
    };

    onClickSkip(){
        this.onClickEnd(true);
    };
}
